Num = input()
m = 0
if len(Num) == 4:
    for i in range(0,4):
        for j in range(i+1,5):
            x = int(Num[i:j])
            c = 0
            for t in range(1,x+1):
                if x%t==0:
                    c=c+1
            if c == 2:
                if x>m:
                    m = x
print(m)

